<!--# layout("/common/layout.html",{"jsBase":"/js/rightRole/rightRole/"}){ -->

<form class="layui-form layui-form-pane" id="addForm"  lay-filter="editform">
    <input type="hidden" name="tenantId" id="tenantId">
    <input type="hidden" name="roleId" id="roleId">
    <div class="layui-row">
        <div class="layui-form-item">
            <div class="layui-inline">
                <div class="layui-input-inline" id="checkBoxDiv">
                    <!--#for(func in funcList) {-->
                    <input type="checkbox" name="functionId" value="${func.functionId}" title="${func.functionName}" ${func.flag=='-1'?'':'checked'}>
                    <!--#} -->
                </div>
            </div>
        </div>
    </div>


    <layui:submitButtons id="addButton" />
</form>
<!--#} -->
<script>
layui.extend({
    loading: '../../../plugins/layui_extends/loading/loading',
}).define([ 'form', 'laydate', 'table','loading','rightRoleApi'], function(exports) {
    var form = layui.form;
    var index = layui.index;
    var view = {
        init:function(){
            Lib.initGenrealForm($("#addForm"),form);
            this.initSubmit();
        },
        initSubmit:function(){
            $("#addButton").click(function(){
                // $("#addButton").hide();
                // $("#addButton-loading").show();
                // $("#addButton-loading").loading();
                var functionIds = "";
                $("input[name='functionId']:checked").each(function (index, item) {
                    if ($("input[name='functionId']:checked").length-1==index) {
                        functionIds += $(this).val();
                    } else {
                        functionIds += $(this).val() + ",";
                    }
                });
                $.ajax({
                    url:Common.ctxPath+"/rightRole/rightRole/func.json",
                    type:"POST",
                    data:{tenantId:${tenantId},roleId:${roleId},functionIds:functionIds},
                    success:function(res){
                        if(res.code==0){
                            parent.window.dataReload();
                            Common.info("操作成功");
                            Lib.closeFrame();
                        }else{
                            Common.info("操作失败");
                            Lib.closeFrame();
                        }
                    }
                });
            });

            $("#addButton-cancel").click(function(){
                Lib.closeFrame();
            });
        }

    }
    view.init();
});
</script>
